package com.luckylo.activemq.controller;

import com.luckylo.activemq.bean.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 模拟通过接口,发布消息到消息队列中
 * 理论上应该是 post 请求,为了方便浏览器地址栏可以直接发送消息,
 * 此处先为 get 请求
 *
 * @user: luckylo
 * @date: 2018-1-17
 */
@RestController
public class MainController {

    @Autowired
    private JmsTemplate jmsTemplate;

    @GetMapping("/aggregate")
    public String publisherAggregate() {

        jmsTemplate.convertAndSend("aggregate", new Message(
                "mysql", "cms", "开始统计云报表"
        ));

        return "publisher aggregate task success";

    }


    @GetMapping("/exportExcel")
    public String publisherExportExcel() {

        jmsTemplate.convertAndSend("exportExcel", new Message(
                "mysql", "monitor", "开始导出快速统计excel报表"
        ));

        return "publisher export excel task success";

    }


    @GetMapping("/exportScoreInfo")
    public String publisherExportScoreInfo() {

        jmsTemplate.convertAndSend("exportScoreInfo", new Message(
                "mysql", "mysql", "开始导出成绩明细"
        ));

        return "publisher export score info success";

    }


    @GetMapping("/exportAggregateResult")
    public String publisherExportAggregateResult() {

        jmsTemplate.convertAndSend("exportAggregateResult", new Message(
                "mysql", "mysql", "开始导出快速统计结果"
        ));

        return "publisher export aggregate result success";

    }


}
